import java.io.*;
import java.util.Enumeration;

import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

@WebServlet(name = "ShowHeadersServlet", value = "/ShowHeadersServlet")
public class ShowHeadersServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.print("<html><head>");
        out.print("<head><title>HTTP Header</title></ head>");
        out.print("<body>");
        out.print("<table border=\"1\">");
        out.print("<tr><td>Header名称</td>");
        out.print("<td>Header值</td></tr>");
        Enumeration<String> headers = request.getHeaderNames();
        while (headers.hasMoreElements()) {
            String paramName = (String) headers.nextElement();
            out.print("<tr><td>" + paramName + "&nbsp&nbsp" + "</td>\n");
            String paramValue = request.getHeader(paramName);
            out.println("<td> " + paramValue + "&nbsp&nbsp" + "</td></tr>\n");
        }
        out.print("</table></body></html>");
    }

    public void destroy() {
    }
}